//1004.最大连续1的个数III
class Solution1 {
    //时间复杂度O(N)，空间复杂度O(1)
    public int longestOnes(int[] nums, int k) {
        int left = 0;
        int right = 0;
        int zero = 0;
        int n = nums.length;       
        int ret = 0;
        for(right = 0;right <n;right++){
            //进窗口
            if(nums[right] == 0){
                    zero++;
                }
            //判断
            while(zero > k){
                //出窗口
                if(nums[left] == 0){
                    zero--;
                }
                left++;
            }
            //更新结果
            ret = Math.max(ret,right-left+1);
        }
       return ret;
    }
}